package com.example.onlinemusic.mapper;

import com.example.onlinemusic.model.Music;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface LoveMusicMapper {
    @Select("select * from lovemusic where user_id=#{userId} and music_id = #{musicId}")
    Music findLoveMusic(int userId, int musicId);

    @Insert("insert into lovemusic(user_id, music_id) values (#{userId}, #{musicId})")
    boolean insertLoveMusic(int userId, int musicId);

    @Select("select m.* from lovemusic lm, music m where m.id = lm.music_id and lm.user_id = #{userId}")
    List<Music> findMusicByUserId(int userId);

    @Select("select m.* from lovemusic lm, music m where m.id = lm.music_id and lm.user_id = #{userId} and title like concat('%',#{musicName},'%')")
    List<Music> findMusicByKeyAndUID(String musicName, int userId);

    @Delete("delete from lovemusic where user_id = #{userId} and music_id=#{musicId}")
    int deleteLoveMusic(int userId, int musicId);

    @Delete("delete from lovemusic where music_id=#{musicId}")
    int deleteLoveMusicById(int musicId);
}
